//
// Copyright (c) 2007-2009 Stuart Morgan.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#import <Foundation/Foundation.h>

@interface CookieStore : NSObject {
 @private
  NSError*        mLastError;
 @protected
  NSMutableArray* mCookies;
}

// Loads cookies from persistant storage. Returns YES if successful. Details
// about failure can be fetched using lastError.
- (BOOL)loadCookies;

// Returns the cookie array previously loaded by loadCookies (with any
// modifications from addCookies:).
- (NSArray*)cookies;

// Adds the given cookies to those previously loaded, then persists them.
// Cookies which conflict with existing cookies will not be added.
// Return YES if successful. Details about failure can be fetched using
// lasteError.
- (BOOL)addCookies:(NSArray*)cookies;

// Returns a descriptive error for the last failure.
- (NSError*)lastError;

#pragma mark Subclass methods

// Subsclasses should override this method to return the cookies from persistant
// storage. If loading fails, the subclass should return nil and set an error.
- (NSArray*)storedCookies;

// Subsclasses should override this method to handle storing and persisting the
// existing cookies. Clients should never call this method, directly, since it
// assumes cookies that conflict with existing cookies have been removed.
// [self cookies] will already have been updated when this is called, so
// subclasses that need access to the entire updated cookie array can use that
// instead of newCookies.
- (BOOL)addNewCookies:(NSArray*)newCookies;

// Sets the last error message using localized strings with the given keys.
// Intended only for use by subclasses.
- (void)setLastErrorWithTitleKey:(NSString*)titleKey
                      messageKey:(NSString*)messageKey;

@end
